import { createSelector } from 'reselect';
import { State } from '../../root-reducer';
import { initialState, UsersState } from './reducer';

const getUsersDomain = () => (state: State): UsersState => state.usersDomain;

const selectUsers = () => createSelector(
  getUsersDomain(),
  usersState => usersState.users || initialState.users
);

const selectIsLoading = () => createSelector(
  getUsersDomain(),
  usersState => usersState.isLoading || initialState.isLoading
);

const selectIsFetched = () => createSelector(
  getUsersDomain(),
  usersState => usersState.isFetched || initialState.isFetched
);

export {
  selectUsers,
  selectIsLoading,
  selectIsFetched
};

export default getUsersDomain;
